library(plotly)
Loading required package: ggplot2
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
library(ggplot2)
library(readr)
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
df <- read.csv('european_pop_gdp_per_capita.csv')
head(df)
plt <- ggplot(df, aes(x=population, y=gdp_per_capita)) + geom_point(aes(color=Country))
plt
pointsToLabel <- c("Austria", "Belgium", "Bulgaria", "Estonia", "France", "Germany", "Italy", "Netherlands", "Spain", "United Kingdom")
#plt2 <- plt + geom_text(aes(label = Country), color = "gray20", fontface='bold', data = subset(df, Country %in% pointsToLabel),check_overlap = TRUE)
plt2 <- plt + geom_text(aes(label = Country), color = "gray20", fontface='bold',check_overlap = TRUE)
plt2
plt3 <- plt2 + scale_x_continuous(name='Population', limits = c(0,90000000))
ggplotly(plt3)
Ok, so this looks pretty scrunched up, and it’s not a particularly useful graph (as I never really thought there was a relationship between population and GDP per capita). But it let me practise using some ggplot2 and plotly features, so it was a useful learning experience.